/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.support.wx.request;

import java.util.SortedMap;

import com.yanlight.support.wx.WxConstants;
import com.yanlight.support.wx.util.SignatureUtil;
import com.yanlight.util.XmlUtil;

/**
 * 
 * @author haolw
 * @time 2017/07/20
 */
public class WxPayNotifyRequest {
	private SortedMap<String, String> notifyMap;

	public WxPayNotifyRequest(String packets) {
		notifyMap = XmlUtil.xmlToSortedMap(packets);
	}

	public String getAppId() {
		return notifyMap.get("appid");
	}

	public String getMchId() {
		return notifyMap.get("mch_id");
	}

	public String getSubMchId() {
		return notifyMap.get("sub_mch_id");
	}

	public String getNonceStr() {
		return notifyMap.get("nonce_str");
	}

	public String getSign() {
		return notifyMap.get("sign");
	}

	public String getResultCode() {
		return notifyMap.get("result_code");
	}

	public String getReturnCode() {
		return notifyMap.get("return_code");
	}

	public String getReturnMsg() {
		return notifyMap.get("return_msg");
	}

	public String getOpenId() {
		return notifyMap.get("openid");
	}

	public String getIsSubscribe() {
		return notifyMap.get("is_subscribe");
	}

	public String getTradeType() {
		return notifyMap.get("trade_type");
	}

	public String getBankType() {
		return notifyMap.get("bank_type");
	}

	public String getTotalFee() {
		return notifyMap.get("total_fee");
	}

	public String getCashFee() {
		return notifyMap.get("cash_fee");
	}

	public String getTransactionId() {
		return notifyMap.get("transaction_id");
	}

	public String getOutTradeNo() {
		return notifyMap.get("out_trade_no");
	}

	public String getTimeEnd() {
		return notifyMap.get("time_end");
	}

	public boolean verifySign(String apiKey) {
		if (!notifyMap.containsKey(WxConstants.SIGN)) {
			return false;
		}
		String sign = notifyMap.get(WxConstants.SIGN);
		String apiSign = SignatureUtil.createApiSign(notifyMap, apiKey);
		return apiSign.equals(sign);
	}

}
